<template>
	<div class="app-container">
		<div class="head-container">
			<div v-if="crud.props.searchToggle">
				<el-input v-model="query.companyName" clearable size="small" placeholder="全表模糊搜索" style="width: 200px;"
					class="filter-item" @keyup.enter.native="crud.toQuery" />
				<rrOperation />
			</div>
			<crudOperation ref="test" :permission="permission" />
		</div>

		<!-- 表单 -->
		<el-dialog append-to-body :close-on-click-modal="false" :before-close="crud.cancelCU"
			:visible.sync="crud.status.cu > 0" :title="crud.status.title" width="680px">
			<el-form ref="form" :model="form" label-width="120px">
				<el-form-item label="幻灯片名称">
					<el-input v-model="form.name" />
				</el-form-item>
				<el-form-item label="幻灯片图片">
					<!-- <el-input v-model="form.imgUrl" /> -->
					<el-upload ref="upload" :limit="1" :file-list="fileList" :action="action" :auto-upload="false"
						:on-success="uploadSuccess" list-type="picture-card" :on-remove="handleRemove">
						<i class="el-icon-plus" />
					</el-upload>
					<el-button style="margin-left: 10px;" size="small" type="success" @click="submitUpload">上传
					</el-button>
				</el-form-item>
				<el-form-item label="权重">
					<el-input v-model="form.weights" />
				</el-form-item>
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button type="text" @click="crud.cancelCU">取消</el-button>
				<el-button :loading="crud.status.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
			</div>
		</el-dialog>

		<!--表格渲染-->
		<el-table ref="table" v-loading="crud.loading" :data="crud.data" style="width: 100%;"
			@selection-change="crud.selectionChangeHandler">
			<el-table-column type="selection" width="55" />
			<el-table-column align="center" prop="name" label="幻灯片名称" />
			<el-table-column align="center" prop="imgUrl" label="幻灯片图片">
				<template slot-scope="scope">
					<el-image style="width: 100px; height: 100px" :preview-src-list="[scope.row.imgUrl]"
						:src="scope.row.imgUrl" fit="contain" />
				</template>
			</el-table-column>
			<el-table-column align="center" prop="weights" label="权重" />
			<el-table-column v-if="checkPer(['admin','menu:edit','menu:del'])" align="center" label="操作" width="150px"
				fixed="right">
				<template slot-scope="scope">
					<udOperation :data="scope.row" :permission="permission" msg="确定删除吗，此操作不能撤销！" />
				</template>
			</el-table-column>
		</el-table>
		<!--分页组件-->
		<pagination />
	</div>
</template>

<script>
	import crudBanner from '@/api/finace_taxation/banner.js'
	import CRUD, {
		presenter,
		header,
		form,
		crud
	} from '@crud/crud'
	import rrOperation from '@crud/RR.operation'
	import crudOperation from '@crud/CRUD.operation'
	import pagination from '@crud/Pagination'
	import udOperation from '@crud/UD.operation'

	// crud交由presenter持有
	const defaultForm = {
		name: null,
		imgUrl: null,
		weights: null
	}

	export default {
		name: 'ContactUs',
		components: {
			pagination,
			crudOperation,
			rrOperation,
			udOperation
		},
		cruds() {
			return CRUD({
				url: 'api/ft/ftBanner',
				title: '幻灯片管理',
				crudMethod: {
					...crudBanner
				}
			})
		},
		mixins: [presenter(), header(), form(defaultForm), crud()],
		data() {
			return {
				delLoading: false,
				permission: {
					add: ['admin', 'menu:add'],
					edit: ['admin', 'menu:edit'],
					del: ['admin', 'menu:del']
				},
				dialogImageUrl: '',
				dialogVisible: false,
				action: '../api/ft/uploadUtil/uploadImage',
				fileList: []
			}
		},
		created() {
			this.crud.optShow = {
				add: true,
				reset: true
			}
		},
		methods: {
			handleRemove(file, fileList) {},
			uploadSuccess(response, file, fileList) {
				this.crud.form.imgUrl = response.result
				this.$refs.upload.clearFiles()
			},
			submitUpload() {
				this.$refs.upload.submit()
			}
		}
	}
</script>
